a, b = map(int, input().split())
n = 1

if a == b: #两个数相同时,最大公约数就是本身
    print(a)
else:
    while a % 2 == 0 and b % 2 == 0:
        a = a // 2
        b = b // 2
        n = n * 2

    while True:
        if a < b:
            a, b = b, a  # a中保证为较大的数    
        c = a - b
        if b == c:
            print(c * n)
            break
        a = b
        b = c
